package com.xy.biz.base.service.impl;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;

/**
 * @author Greekn Zhang
 * @date 2021/7/26 13:53
 * @description
 */
@Service
public class DictInitializeEventBus {
    private List<Consumer<Long>> afterHandlerList = new CopyOnWriteArrayList<>();

    @Transactional
    public void addHandle(Consumer<Long> handler) {
        afterHandlerList.add(handler);
    }


    @Transactional
    public void fireHandler(Long id) {
        afterHandlerList.forEach(e -> e.accept(id));
    }
}
